package com.youchuang.action.main;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.bean.Book;
import com.youchuang.bean.Comment;
import com.youchuang.common.Constant;
import com.youchuang.service.MainService;

import net.sf.json.JSONArray;

/**
 * 书本详细信息
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/main")
@ParentPackage("shopping-default")
public class BookViewAction extends BaseAction {
	private Logger logger = Logger.getLogger(BookViewAction.class.getSimpleName());
	private Book book;
	private String id;
	private List<Comment> comments;
	
	@Resource
	private MainService mainService;

	@Action(value = "bookView", results = {
			@Result(name = Constant.BOOKVIEW, location = "/WEB-INF/jsp/main/product.jsp") })
	public String execute() throws Exception {
		logger.info("excetion is execute");

		book = mainService.findBookById(id);
		comments = mainService.findCommentByProductId(id);

		logger.info("response json comments =" + JSONArray.fromObject(comments).toString());
		return Constant.BOOKVIEW;
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}

}
